package com.example.demo.day0303;

import com.sun.corba.se.spi.orbutil.proxy.InvocationHandlerFactory;

import java.lang.reflect.*;
import java.lang.reflect.InvocationHandler;

public class MethodSelector implements InvocationHandler{
    private Object proxied;//被代理的对象

    public MethodSelector(Object proxied) {
        this.proxied = proxied;
    }

    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if (method.getName().equals("interesting"))
            System.out.println("Proxy detected the interesting method");
        return method.invoke(proxied, args);//执行的是指定代理对象的指定的方法
    }
}


